< Prev(J) / Next(K) > / View :

Filename: /text/sbasic/shared/01010210.xhp

(section: modular) (bookmark: bm_id4488967)
fundamentals
subroutines
variables;global and local
modules;subroutines and functions

基本
サブルーチン
変数;グローバルとローカル
モジュール;サブルーチンと関数

Basics
基本(hd_id3154927.1)

This section provides the fundamentals for working with Office Basic.
このセクションでは、Office Basic の基本について説明します。(par_id3156023.14)

(/section: modular)

Office Basic code is based on subroutines and functions that are specified between sub...end sub and function...end function sections. Each Sub or Function can call other Subs and Functions. If you take care to write generic code for a Sub or Function, you can probably re-use it in other programs. See also Procedures and Functions.
Office Basic のコードは、Sub...End SubFunction...End Function セクションで定義するサブルーチンおよび関数から構成されます。1 つの Sub および Function からは、他の Sub や Function を呼び出すこともできます。Sub や Function を記述する際に、可能な限り汎用的なコードにしておくと、他のプログラムで再利用できる可能性が高まります。プロシージャーおよび関数 も参照してください。(par_id3147560.2)

What is a Sub?
Sub (サブルーチン) の用途(hd_id3150398.3)

Sub is the short form of subroutine, that is used to handle a certain task within a program. Subs are used to split a task into individual procedures. Splitting a program into procedures and sub-procedures enhances readability and reduces the error-proneness. A sub possibly takes some arguments as parameters but does not return any values back to the calling sub or function, for example:
Sub とは、サブルーチン (subroutine) を省略したもので、1 つのプログラム中で実行する特定のタスクをブロック化する際に使用します。 サブルーチンを利用することで、1 つのタスクを複数のプロシージャーに分割することができます。 プログラムの構造を複数のプロシージャーやサブプロシージャーに分割すると、コードの可読性が高まると同時に、エラーの発生を抑える効果も期待できます。 下記の例のように、サブルーチンにはパラメータとして複数の引数を渡すことも可能ですが、呼び出し元のサブルーチンや関数に戻り値を返すことはできません。(par_id3148797.4)

DoSomethingWithTheValues(MyFirstValue,MySecondValue)
DoSomethingWithTheValues(MyFirstValue,MySecondValue)(par_id3150868.15)

What is a Function?
Function (関数) の用途(hd_id3156282.5)

A function is essentially a sub, which returns a value. You may use a function at the right side of a variable declaration, or at other places where you normally use values, for example:
Function の基本的な機能はサブルーチンと同じですが、戻り値を返せるという点が異なります。下記の例のように、変数宣言部の右側に関数を配置することも可能で、通常の値の代わりに直接関数を記述することもできます。(par_id3156424.6)

MySecondValue = myFunction(MyFirstValue)
MySecondValue = myFunction(MyFirstValue)(par_id3146985.7)

Global and local variables
大域および局所変数(hd_id3153364.8)

Global variables are valid for all subs and functions inside a module. They are declared at the beginning of a module before the first sub or function starts.
大域変数とは、1 つのモジュール内にあるすべてのサブルーチンと関数で使用できる変数のことです。これらの宣言は、モジュール内のすべてのサブルーチンや関数より前に記述する必要があります。(par_id3151112.9)

Variables that you declare within a sub or function are valid only inside this sub or function. These variables override global variables with the same name and local variables with the same name coming from superordinate subs or functions.
個々のサブルーチンや関数の中で宣言した変数は、該当するサブルーチンや関数の内部でのみ使用できます。これらの変数は、上位のサブルーチンや関数から継承した局所変数や大域変数と同じ名前があっても優先的に使用されます。(par_id3154012.10)

Structuring
構造化(hd_id3150010.11)

After separating your program into procedures and functions (Subs and Functions), you can save these procedures and functions as files for reuse in other projects. Office Basic supports Modules and Libraries. Subs and functions are always contained in modules. You can define modules to be global or part of a document. Multiple modules can be combined to a library.
プログラムをプロシージャーや関数 (Sub および Function) に分割して記述した場合、個々のプロシージャーや関数をファイルに保存して、他のプロジェクトで再使用することができます。Office Basic には、モジュールとライブラリの機能が用意されています。サブルーチンや関数は、常にモジュール内に定義されます。モジュールは、大域的に使用することも、特定ドキュメント内部でのみ使用することもできます。また複数のモジュールをまとめて、1 つのライブラリとすることもできます。(par_id3153727.12)

You can copy or move subs, functions, modules and libraries from one file to another by using the Macro dialog.
サブルーチン、関数、モジュール、ライブラリは、ダイアログ マクロ を使用することで、ファイル間のコピーおよび移動が行えます。(par_id3152578.13)


< Prev / Next >